package at.moop.up;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class UpSoldier {
	
	public static boolean hasFtpCredentials(Context c){
		return !PreferenceManager.getDefaultSharedPreferences(c).getString(Configuration.PREF_FTP_SERVER, "").equals("");
	}
	
	public static FTPCredentials getFtpCredentials(Context c){
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
		FTPCredentials cred = new FTPCredentials();
		
		cred.setPassword(prefs.getString(Configuration.PREF_FTP_PASSWORD, ""));
		cred.setUser(prefs.getString(Configuration.PREF_FTP_USER, ""));
		cred.setServer(prefs.getString(Configuration.PREF_FTP_SERVER, ""));
		
		return cred;
	}
	
	public static void storeCredentials(FTPCredentials credentials, Context c){
		SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(c).edit();
		prefs.putString(Configuration.PREF_FTP_PASSWORD, credentials.getPassword());
		prefs.putString(Configuration.PREF_FTP_USER, credentials.getUser());
		prefs.putString(Configuration.PREF_FTP_SERVER, credentials.getServer());
		prefs.commit();
	}

}
